//
//  InsuranceCell.m
//  car
//
//  Created by chenxu on 3/31/15.
//  Copyright (c) 2015 chenxu. All rights reserved.
//

#import "InsuranceCell.h"
@interface InsuranceCell ()
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UIImageView *img;
@property BOOL checked;
@end


@implementation InsuranceCell


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.accessoryType = UITableViewCellAccessoryNone;
        _checked = false;
        if (!_titleLabel) {
            _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 7, 300, 30)];
            _titleLabel.backgroundColor = [UIColor clearColor];
            _titleLabel.font = [UIFont systemFontOfSize:16];
            _titleLabel.textColor = [UIColor blackColor];
            [self.contentView addSubview:_titleLabel];
        }
        if (!_img) {
            _img = [[UIImageView alloc]initWithFrame:CGRectMake(20, self.contentView.frame.size.height/2-10, 20, 20)];
            _img.image = [UIImage imageNamed:@"cb_normal"];
            [self.contentView addSubview:_img];
        }
        
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
}
- (void)setTitle:(NSString *)str{
    _titleLabel.text = str;
}

- (void)setMyImage:(UIImage *)image{
    _img.image = image;
}

- (void)changestate{
    if (_checked) {
        _img.image = [UIImage imageNamed:@"cb_normal"];
        _checked = false;
    }
    else{
        _img.image = [UIImage imageNamed:@"cb_checked"];
        _checked = true;
    }
}

+ (CGFloat)cellHeight{
    return 44.0;
}

- (BOOL)isChecked{
    return _checked;
}

- (void)check{
    if (_checked == false) {
        _checked = true;
        [self setMyImage:[UIImage imageNamed:@"cb_checked"]];
    }
}
@end
